package top.oneit.jdownload.test;

import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;

import java.util.Date;

/**
 * @author lingkang
 */
public class MySonA extends MyStageCommon {
    public Button button;

    public MySonA() {
        setTitle("子窗口A");
        MyParent parent = getStage(MyParent.class);
        Label label = new Label("我是儿子A");
        button = new Button("关闭父窗口");
        button.setOnAction(event -> {
            System.out.println(parent.getTitle());
            parent.close();
        });
        button.setLayoutY(40);

        Button open = new Button("打开父窗口");
        open.setLayoutY(80);
        open.setOnAction(event -> {
            if (parent.button != null)
                parent.button.setText("子调用父的对象" + new Date());// 父子传参
            parent.show();
        });

        Button exit = new Button("exit");
        exit.setLayoutY(120);
        exit.setOnAction(event -> {
            System.exit(0);
        });

        AnchorPane pane = new AnchorPane(label, button, open, exit);
        pane.setPrefWidth(300);
        pane.setPrefHeight(200);
        setScene(new Scene(pane));
    }
}
